#!/bin/sh
# Grid Engine options (lines prefixed with #$)
#$ -N runPedigreeTest
#$ -cwd                  
#$ -l h_rt=12:00:00
#$ -l h_vmem=12G
#$ -pe sharedmem 1
#$ -e logs
#$ -o logs

submit_rep () {
    rep=$1
    # Figure 1: HD Markers
    for nHD in 100 500 1000; do
        cp -r base/* data/hd_markers/dataFor-10-${nHD}-1

        for trait in {1..100}; do 
            ./runCreateTrait.sh hd_markers $rep 10 $nHD 1  0.5 $trait noTrain
        done
    done

    # Figure 1: Base set. Vary gvar + training
    cp -r base/* data/base/dataFor-10-500-1
    for gvar in 0.1 0.2 0.3 0.4 0.5 0.6 0.7; do
        for trait in {1..100}; do 
            ./runCreateTrait.sh base $rep 10 500 1    $gvar $trait noTrain
        done
    done

    for trait in {1..100}; do 
        ./runCreateTrait.sh base $rep 10 500 1    0.5 $trait train
    done

    # Figure 1: nChr

    for nChr in 5 10 15 20; do
        cp -r base/* data/num_chr/dataFor-${nChr}-500-1

        for trait in {1..100}; do 
            ./runCreateTrait.sh num_chr $rep $nChr 500 1   0.5 $trait noTrain
        done
    done

    # Figure 1: map length

    for map in 0.5 1 2 4; do
        cp -r base/* data/map_len/dataFor-10-500-${map}
        for trait in {1..100}; do 
            ./runCreateTrait.sh map_len $rep 10 500 $map   0.5 $trait noTrain
        done
    done

}


if [ $1 = submit ] ; then 

    for rep in {1..10}; do
        submit_rep $rep &
    done
    exit 1
fi


if [ $1 = test ] ; then 
    # cp -r base/* data/hd_markers/dataFor-10-100-1
    # ./runCreateTrait.sh hd_markers 10 100 1 1 7 noTrain
    cp -r base/* data/base/dataFor-10-500-1

    ./runCreateTrait.sh base 1 10 500 1 1 7 train
    exit 1
fi


tinyPeel=`pwd`/tinypeel/src/tinyPeel-script.py

. /etc/profile.d/modules.sh

. ~/.bashrc
export OMP_NUM_THREADS=$NSLOTS
export MKL_NUM_THREADS=$NSLOTS

sim=$1
rep=$2
nChr=$3
nSnp=$4
maplength=$5

gvar=$6
trait=$7
train=$8

fileDir=data/$sim/$rep/dataFor-$nChr-$nSnp-$maplength

cd $fileDir

folder=traits/gvar-$gvar/$trait/
mkdir -p $folder

echo Creating traits
echo $gvar $train $folder
Rscript createTraitTraining.r $gvar $train $folder

echo Traits created
